package com.foreknow.homework.book;
import java.util.Scanner;


public class Books {
    public void books(){

    }

    public BookBean[] b(){
        BookBean[] b=new BookBean[3];
        BookBean b1=new BookBean();
        b1.setId(1);
        b1.setBook("java");
        b1.setPrice(33.45);
        b1.setNum(50);
        BookBean b2=new BookBean();
        b2.setId(2);
        b2.setBook("jsp");
        b2.setPrice(55.45);
        b2.setNum(150);
        BookBean b3=new BookBean();
        b3.setId(3);
        b3.setBook("ssm");
        b3.setPrice(77.45);
        b3.setNum(250);
        b[0]=b1;
        b[1]=b2;
        b[2]=b3;
        return b;
    }

   public OrderBean[] o() {
        BookBean bookBean=new BookBean();
        OrderBean[] o = new OrderBean[3];
        o[0]= new OrderBean();
        o[1] = new OrderBean();
        o[2] = new OrderBean();
       for (int j = 0; j < o.length; j++) {
           o[j].setBook(bookBean.getBook());
           o[j].setPrice(bookBean.getPrice());
           o[j].setBnum(bookBean.getNum());
       }
        return o;
    }

    public void BookOrder() {
        BookBean bookBean = new BookBean();
        Books books = new Books();
        Scanner input = new Scanner(System.in);
        BookBean[] b = books.b();
        System.out.println("请输入图书编号：");
        bookBean.setId(input.nextInt());
        int bid=bookBean.getId();
        for(int i = 0; i<b.length; i++)
        if (bookBean.getId()==bid) {
            System.out.println("请输入购买数量：");
            bookBean.setNum(input.nextInt());
            o();
            break;
        } else {
            System.out.println("没有此编号的图书，请重新输入");
            BookOrder();
        }
    }


    public double sum(double sum){
        SumBean sumBean=new SumBean();
        BookBean bookBean=new BookBean();
        OrderBean orderBean = new OrderBean();
        for (int i=0;i<3;i++)
            sum+=bookBean.getPrice()*orderBean.getBnum();
        sumBean.setSum(sum);
        return sum;
    }

    public static void main(String[] args) {
        Books books=new Books();
        SumBean sumBean = new SumBean();
        BookBean[] bk=books.b();

        Scanner input = new Scanner(System.in);
        for (BookBean book:bk)
            System.out.println(book.getId()+" "+book.getBook()+
                    "  "+book.getPrice()+"   "+book.getNum());
        books.BookOrder();
        System.out.println("是否继续购买？（y/n）");
        String choo=input.next();
        if (choo.equals("y")){
            books.BookOrder();
        }else if(choo.equals("n")) {
            books.sum(0);
            System.out.println("订单的总额为：" + sumBean.getSum());
        }
    }
}
